package com.yicong.ants.utils;

import com.cchao.simplelib.util.ThreadHelper;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpManager {

//    private static final String BROADCAST_IP = "192.168.4.228";
    private static final String BROADCAST_IP = "47.108.86.88";
    private static final int BUFFER_LENGTH = 1024;
    private static final int CLIENT_PORT = 9512;//端口号



    public static void sendMessage(String message) {
        ThreadHelper.execute(() -> {
            try {
                DatagramSocket client = new DatagramSocket(CLIENT_PORT);
                InetAddress targetAddress = InetAddress.getByName(BROADCAST_IP);
                DatagramPacket packet = new DatagramPacket(message.getBytes(), message.length(), targetAddress, CLIENT_PORT);
                client.send(packet);
                client.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }

}
